<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <title>webrx</title>
</head>
<body>
<h2>fetch file upload</h2>
<input multiple name="fss" type="file">
<button>上多文件</button>
<script>
    function uploads() {
        let d = new FormData();
        var f = document.querySelector("input[name='fss']");
        d.append('author', '李勇');
        for (const file of f.files) {
            d.append('photo[]', file, file.name)
        }
        fetch('uploads.php', {
            method: 'POST',
            headers: {token: '1111122222'},
            body: d
        }).then(e => e.json())
            .catch(e => console.error('Error:', e))
            .then(e => console.log('上传成功:', e));
    }

    let ub = document.querySelectorAll('button')[0]
    ub.addEventListener('click', uploads)
</script>
</body>
</html>